package instance;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by zc on 17-4-24.
 */
public class Main {
    public static void main(String[] args) {
//        ApplicationContext factory = new ClassPathXmlApplicationContext("spring-config.xml");
//        instance.HelloWorld bean = (instance.HelloWorld) factory.getBean(instance.HelloWorldImpl.class);
//        bean.say();

//        sayById();

//         sayByName();

//        sayByNameAndId();

//        sayByMultiName();

        sayWithArgs();
    }


    public static void sayById() {
        ApplicationContext fatory = new ClassPathXmlApplicationContext("conf/spring-config.xml");
        HelloWorld helloworld = fatory.getBean("helloWorld", HelloWorld.class);
        helloworld.say();
    }

    public static void sayByName() {
        ApplicationContext fatory = new ClassPathXmlApplicationContext("conf/spring-config.xml");
        HelloWorld helloworld = fatory.getBean("helloWorldByName", HelloWorld.class);
        helloworld.say();
    }

    public static void sayByNameAndId() {
        ApplicationContext fatory = new ClassPathXmlApplicationContext("conf/spring-config.xml");
        HelloWorld helloworld1 = fatory.getBean("helloWorldByName02", HelloWorld.class);
        helloworld1.say();
        HelloWorld helloworld2 = fatory.getBean("helloWorldByld02", HelloWorld.class);
        helloworld2.say();
    }

    public static void sayByMultiName() {
        ApplicationContext fatory = new ClassPathXmlApplicationContext("conf/spring-config.xml");
        HelloWorld helloworld1 = fatory.getBean("bean1", HelloWorld.class);
        helloworld1.say();
        HelloWorld helloworld2 = fatory.getBean("bean2", HelloWorld.class);
        helloworld2.say();
        HelloWorld helloworld3 = fatory.getBean("bean3", HelloWorld.class);
        helloworld3.say();
    }

    public static void sayWithArgs() {
        ApplicationContext fatory = new ClassPathXmlApplicationContext("conf/spring-config.xml");
        HelloWorld helloWorldWithArgs = (HelloWorld) fatory.getBean("helloWorldWithArgs");
        helloWorldWithArgs.say();
    }
}
